//
//  SITableViewCell.m
//  UI12_UITableVIewCellHomeworkSecond
//
//  Created by dllo on 16/6/21.
//  Copyright © 2016年 司昌宝. All rights reserved.
//

#import "SITableViewCell.h"
#define kWidth self.frame.size.width
#define kHeight self.frame.size.height
#import "Contact.h"
@interface SITableViewCell ()

@property (nonatomic,retain) UIImageView *headerImageView;
@property (nonatomic,retain) UILabel *nameLabel;
@property (nonatomic,retain) UILabel *numberLabel;

@end



@implementation SITableViewCell
-(void)dealloc{
    [_headerImageView release];
    [_nameLabel release];
    [_numberLabel release];
    [_cellContact release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.headerImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.headerImageView];
        [_headerImageView release];
        
        self.nameLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.nameLabel];
        [_nameLabel release];
        
        self.numberLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.numberLabel];
        [_numberLabel release];
        
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    //设置视图属性
    /** movieImageView */
    self.headerImageView.frame = CGRectMake(10, 10, kHeight - 20, kHeight - 20);
    self.headerImageView.backgroundColor = [UIColor orangeColor];
    self.headerImageView.layer.masksToBounds = YES;
    self.headerImageView.layer.cornerRadius = (kHeight - 20) * 0.5;
    /** nameLabel */
    self.nameLabel.frame = CGRectMake(_headerImageView.frame.size.width + 40, 20, kWidth * 0.5, kHeight * 0.2);
    self.nameLabel.backgroundColor = [UIColor greenColor];
    
    /** idLabel */
    self.numberLabel.frame = CGRectMake(_headerImageView.frame.size.width + 40, 40 + kHeight * 0.2, kWidth * 0.5, kHeight * 0.2);
    self.numberLabel.backgroundColor = [UIColor blueColor];
    
    
}

-(void)setCellContact:(Contact *)cellContact{
    if (_cellContact != cellContact){
        [_cellContact release];
        _cellContact = [cellContact retain];
    }
    
    UIImage *image = [UIImage imageNamed:cellContact.header];
    _headerImageView.image = image;
    _nameLabel.text = cellContact.name;
    _numberLabel.text = cellContact.number;
    
    
    
}



@end
